package com.atguigu.gulimall.search.conf;

import org.apache.http.HttpHost;
import org.elasticsearch.client.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <简述>
 * 1-导入依赖
 * 2-编写配置 注入 RestHighLevelClient
 * 3-官方文档操作
 *  https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high.html
 * <详细描述>
 * @author syf
 * @date 2022/3/18 16:05
 */

//@SpringBootConfiguration
@Configuration
public class GulimallElasticSearchConfig {


    public static final RequestOptions COMMON_OPTIONS;
    static {
        RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
//        builder.addHeader("Authorization", "Bearer " + TOKEN);
//        builder.setHttpAsyncResponseConsumerFactory(
//                new HttpAsyncResponseConsumerFactory
//                        .HeapBufferedResponseConsumerFactory(30 * 1024 * 1024 * 1024));
        COMMON_OPTIONS = builder.build();
    }

    @Bean
    public RestHighLevelClient esRestCenlent(){
        RestClientBuilder builder = null;

        builder = RestClient.builder(new HttpHost("192.168.1.152", 9200, "http"));

        RestHighLevelClient client = new RestHighLevelClient(builder);

//        RestHighLevelClient client = new RestHighLevelClient(
//                RestClient.builder(
//                        new HttpHost("192.168.1.152", 9200, "http"));
        return client;
    }

}
